package com.choosefine.springboot.devops.base.test;


import org.apache.http.impl.client.DefaultHttpClient;

/**
 * Created by Administrator on 2017/1/5 0005.
 */
public class test2 {
    // http客户端
    public static DefaultHttpClient httpclient;

    static {
        httpclient = new DefaultHttpClient();
        //httpclient = (DefaultHttpClient) HttpClientConnectionManager.getSSLInstance(httpclient); // 接受任何证书的浏览器客户端
    }

    public static void main(String[] args) {
        try {
            // 获取accessToken -参数appid，secret
            String accessToken = getAccessToken("appid", "secret");
            System.out.println(accessToken);
            // 创建菜单
            //String s = "{\"button\":[{\"name\":\"休闲娱乐\",\"sub_button\":[{\"type\":\"click\",\"name\":\"笑话大全\",\"key\":\"m_joke\"},{\"type\":\"click\",\"name\":\"内涵段子\",\"key\":\"m_duanzi\"},{\"type\":\"click\",\"name\":\"爆笑图片\",\"key\":\"m_laughImg\"}]},{\"name\":\"实用工具\",\"sub_button\":[{\"type\":\"click\",\"name\":\"天气查询\",\"key\":\"m_weather\"},{\"type\":\"click\",\"name\":\"公交查询\",\"key\":\"m_bus\"}]},{\"type\":\"click\",\"name\":\"关于企特\",\"key\":\"m_about\"}]}";
            String s = "{\"button\":[{\"name\":\"休闲娱乐\",\"sub_button\":[{\"type\":\"click\",\"name\":\"笑话大全\",\"key\":\"m_joke\"},{\"type\":\"click\",\"name\":\"内涵段子\",\"key\":\"m_duanzi\"},{\"type\":\"click\",\"name\":\"爆笑图片\",\"key\":\"m_laughImg\"}]},{\"name\":\"实用工具\",\"sub_button\":[{\"type\":\"click\",\"name\":\"天气查询\",\"key\":\"m_weather\"},{\"type\":\"click\",\"name\":\"公交查询\",\"key\":\"m_bus\"},{\"type\":\"click\",\"name\":\"功能菜单\",\"key\":\"m_sysmenu\"}]},{\"name\":\"消息示例\",\"sub_button\":[{\"type\":\"click\",\"name\":\"关于企特\",\"key\":\"m_about\"},{\"type\":\"click\",\"name\":\"图文消息\",\"key\":\"m_imgmsg\"},{\"type\":\"click\",\"name\":\"音乐消息\",\"key\":\"m_musicmsg\"}]}]}";
            String res = createMenu(s, accessToken);
            System.out.println(res);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    /**
     * 创建菜单
     */
    public static String createMenu(String params, String accessToken) throws Exception {
//        HttpPost httpost = ("https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + accessToken);
//        httpost.setEntity(new StringEntity(params, "UTF-8"));
//        HttpResponse response = httpclient.execute(httpost);
//        String jsonStr = EntityUtils.toString(response.getEntity(), "utf-8");
//        System.out.println(jsonStr);
//        JSONObject object = JSON.parseObject(jsonStr);
//        return object.getString("errmsg");
        return null;
    }

    /**
     * 获取accessToken
     */
    public static String getAccessToken(String appid, String secret) throws Exception {
//        HttpGet get = HttpClientConnectionManager.getGetMethod("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret);
//        HttpResponse response = httpclient.execute(get);
//        String jsonStr = EntityUtils.toString(response.getEntity(), "utf-8");
//        JSONObject object = JSON.parseObject(jsonStr);
//        return object.getString("access_token");
        return null;
    }

    /**
     * 查询菜单
     */
    public static String getMenuInfo(String accessToken) throws Exception {
//        HttpGet get = HttpClientConnectionManager.getGetMethod("https://api.weixin.qq.com/cgi-bin/menu/get?access_token=" + accessToken);
//        HttpResponse response = httpclient.execute(get);
//        String jsonStr = EntityUtils.toString(response.getEntity(), "utf-8");
//        return jsonStr;
        return null;    }

    /**
     * 删除自定义菜单
     */
    public static String deleteMenu(String accessToken) throws Exception {
//        HttpGet get = httpclient.execute("https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=" + accessToken);
//        HttpResponse response = httpclient.execute(get);
//        String jsonStr = EntityUtils.toString(response.getEntity(), "utf-8");
//        JSONObject object = JSON.parseObject(jsonStr);
//        return object.getString("errmsg");
        return null;
    }


}
